package com.hui.controller;

import com.hui.entity.ResourceCategory;
import com.hui.entity.ResponseResult;
import com.hui.service.ResourceCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 李昭辉
 * @Date: 2021/08/08/15:35
 * @Description:
 */
@RestController
@RequestMapping("/ResourceCategory")
public class ResourceCategoryController {
    @Autowired
    private ResourceCategoryService resourceCategoryService;

    // 查询资源分类信息列表
    @RequestMapping("/findAllResourceCategory")
    public ResponseResult findAllResourceCategory() {
        List<ResourceCategory> list = resourceCategoryService.getAllResourceCategory();
        return new ResponseResult(true, 200, "查询成功", list);
    }

    // 添加& 修改资源分类
    @RequestMapping("/saveOrUpdateResourceCategory")
    public ResponseResult saveOrUpdateResourceCategory(@RequestBody ResourceCategory resourceCategory) {
        if (resourceCategory.getId() == null) {
            // 新增
            resourceCategoryService.saveCategory(resourceCategory);
            return new ResponseResult(true, 200, "添加成功", null);

        } else {
            // 修改
            resourceCategoryService.updateCategory(resourceCategory);
            return new ResponseResult(true, 200, "修改成功", null);
        }
    }

    // 删除资源分类信息
    @RequestMapping("/deleteResourceCategory")
    public ResponseResult deleteResourceCategory(Integer id){
        resourceCategoryService.deleteCategory(id);
        return new ResponseResult(true, 200, "删除成功", null);
    }

}
